//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include <elasys_server.h>
#include "wincetypes.h"
#include "CMalloc.h"

CMalloc* g_pMalloc = NULL;

EXTERN_C void* gAlloc(int size)
{
    return g_pMalloc->Alloc(size);
}

EXTERN_C void* gRealloc(void *pMem, int size)
{
    return g_pMalloc->Realloc(pMem, size);
}

EXTERN_C void gFree(void *pMem)
{
    g_pMalloc->Free(pMem);
}

EXTERN_C TIME _GetTickCount()
{
    return (TIME)0;
}

PVoid CMalloc::Alloc(size_t Size)
{
    return malloc(Size);
}

PVoid CMalloc::Realloc(PVoid pMem, size_t NewSize)
{
    return realloc(pMem, NewSize);
}

void CMalloc::Free(PVoid pMem)
{
    free(pMem);
}

size_t CMalloc::GetSize(PVoid pMem)
{
    return 0;
}


EXTERN_C void StackTrack(int index)
{
    return ;
}

EXTERN_C void HeapMemoryStatus()
{
    return ;
}

EXTERN_C void CheckHeapMemory(TIME TFlagTime)
{
    return ;
}

EXTERN_C int GetMemState(char *pBuffer)
{
    return 0;
}

EXTERN_C int GetHeapState()
{
    return 0;
}

EXTERN_C Boolean HeapSpySwitch(int iState)
{
    return FALSE;
}

EXTERN_C BOOL __stdcall _DllMainCRTStartup(
    HANDLE hDllHandle,
    UInt32 dwReason,
    PVoid preserved)
{
    g_pMalloc = new CMalloc();
    if (NULL == g_pMalloc) {
        return FALSE;
    }

    return TRUE;
}

EXTERN_C CMalloc *GetGlobalMallocPointer()
{
    return g_pMalloc;
}
